<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>C 和 C++ 可变参数介绍 | 夜悊的技术小宅</title><meta name="author" content="夜悊"><meta name="copyright" content="夜悊"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="前言C 和 C++ 可变参数介绍。  概念可变（长）&#x2F;不定（长）参数：函数可以接收任意数量的参数（函数在声名和定义时不明确参数的数量）  C 的可变参数参数列表 #va_list 4组宏头文件  &lt;stdarg.h&gt;  宏  #va_list：类型宏；参数列表 #va_start()：函数宏；va_list 指向参数列表的第一个参数 #va_arg()：函数宏；依据类型，va">
<meta property="og:type" content="article">
<meta property="og:title" content="C 和 C++ 可变参数介绍">
<meta property="og:url" content="http://example.com/2023/11/08/C%20%E5%92%8C%20C++%20%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0%E4%BB%8B%E7%BB%8D/index.html">
<meta property="og:site_name" content="夜悊的技术小宅">
<meta property="og:description" content="前言C 和 C++ 可变参数介绍。  概念可变（长）&#x2F;不定（长）参数：函数可以接收任意数量的参数（函数在声名和定义时不明确参数的数量）  C 的可变参数参数列表 #va_list 4组宏头文件  &lt;stdarg.h&gt;  宏  #va_list：类型宏；参数列表 #va_start()：函数宏；va_list 指向参数列表的第一个参数 #va_arg()：函数宏；依据类型，va">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/img/cover6.png">
<meta property="article:published_time" content="2023-11-08T12:38:00.000Z">
<meta property="article:modified_time" content="2024-02-28T03:26:35.467Z">
<meta property="article:author" content="夜悊">
<meta property="article:tag" content="C++">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/img/cover6.png"><link rel="shortcut icon" href="/img/favicon2.png"><link rel="canonical" href="http://example.com/2023/11/08/C%20%E5%92%8C%20C++%20%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0%E4%BB%8B%E7%BB%8D/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css?v=4.13.0"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0.33/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":true,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: 夜悊","link":"链接: ","source":"来源: 夜悊的技术小宅","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid@4.11.1/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'C 和 C++ 可变参数介绍',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-02-28 11:26:35'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><link rel="stylesheet" href="/css/my_css.css"><meta name="generator" content="Hexo 7.3.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">92</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">15</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">15</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw fa fa-bookmark"></i><span> 笔记目录</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw fa fa-blog"></i><span> 其他博客</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://blog.csdn.net/m0_62083249"><i class="fa-fw fa fa-link"></i><span> CSDN</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.zhihu.com/people/ye-zhe-ning"><i class="fa-fw fa fa-link"></i><span> 知乎</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw fa fa-sitemap"></i><span> 代码仓库</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://gitee.com/yezhening"><i class="fa-fw fa fa-link"></i><span> Gitee</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://github.com/yezhening"><i class="fa-fw fa fa-link"></i><span> Github</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about_me/"><i class="fa-fw fas fa-user"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/cover6.png')"><nav id="nav"><span id="blog-info"><a href="/" title="夜悊的技术小宅"><span class="site-name">夜悊的技术小宅</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw fa fa-bookmark"></i><span> 笔记目录</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw fa fa-blog"></i><span> 其他博客</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://blog.csdn.net/m0_62083249"><i class="fa-fw fa fa-link"></i><span> CSDN</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.zhihu.com/people/ye-zhe-ning"><i class="fa-fw fa fa-link"></i><span> 知乎</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw fa fa-sitemap"></i><span> 代码仓库</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://gitee.com/yezhening"><i class="fa-fw fa fa-link"></i><span> Gitee</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://github.com/yezhening"><i class="fa-fw fa fa-link"></i><span> Github</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about_me/"><i class="fa-fw fas fa-user"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">C 和 C++ 可变参数介绍</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-11-08T12:38:00.000Z" title="发表于 2023-11-08 20:38:00">2023-11-08</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-02-28T03:26:35.467Z" title="更新于 2024-02-28 11:26:35">2024-02-28</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/C/">C++</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="C 和 C++ 可变参数介绍"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>C 和 C++ 可变参数介绍。</p>
<hr>
<h1 id="概念"><a href="#概念" class="headerlink" title="概念"></a>概念</h1><p>可变（长）&#x2F;不定（长）参数：<strong>函数</strong>可以接收任意数量的参数（函数在声名和定义时不明确参数的数量）</p>
<hr>
<h1 id="C-的可变参数"><a href="#C-的可变参数" class="headerlink" title="C 的可变参数"></a>C 的可变参数</h1><h2 id="参数列表-va-list-4组宏"><a href="#参数列表-va-list-4组宏" class="headerlink" title="参数列表 #va_list 4组宏"></a>参数列表 #va_list 4组宏</h2><p>头文件</p>
<ul>
<li>&lt;stdarg.h&gt;</li>
</ul>
<p>宏</p>
<ul>
<li>#va_list：类型宏；参数列表</li>
<li>#va_start()：函数宏；va_list 指向参数列表的第一个参数</li>
<li>#va_arg()：函数宏；依据类型，va_list 指向参数列表的下一个参数</li>
<li>#va_end()：函数宏；清理 va_list</li>
</ul>
<p>底层原理</p>
<ul>
<li>#va_list：字符指针</li>
<li>#va_start()：指针指向第一个元素</li>
<li>#va_arg()：指针指向下一个元素</li>
<li>#va_end()：指针置空</li>
</ul>
<p>缺点</p>
<ul>
<li>代码逻辑需要明确参数的数量和每个参数的类型</li>
<li>…</li>
</ul>
<h2 id="代码示例"><a href="#代码示例" class="headerlink" title="代码示例"></a>代码示例<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdarg.h&gt;</span> <span class="comment">// #va_list、#va_start()、#va_arg()、#va_end()</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 形参的一般形式：</span></span><br><span class="line"><span class="comment">// num：参数数量</span></span><br><span class="line"><span class="comment">// ...：参数列表</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">print</span><span class="params">(<span class="type">int</span> num, ...)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">// 1. 定义 va_list</span></span><br><span class="line">    va_list para_list; <span class="comment">// 类型宏；参数列表</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 2. 初始化 va_list</span></span><br><span class="line">    va_start(para_list, num); <span class="comment">// 函数宏；va_list 指向参数列表的第一个参数</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 3. 遍历 va_list</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i &lt; num; ++i)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;%d &quot;</span>, va_arg(para_list, <span class="type">int</span>)); <span class="comment">// 函数宏；依据类型，va_list 指向参数列表的下一个参数</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 4. 清理 va_list</span></span><br><span class="line">    va_end(para_list); <span class="comment">// 函数宏；清理 va_list</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">    print(<span class="number">2</span>, <span class="number">0</span>, <span class="number">1</span>);</span><br><span class="line">    <span class="comment">// 实参的一般形式：</span></span><br><span class="line">    <span class="comment">// 2：参数数量</span></span><br><span class="line">    <span class="comment">// 0 1：参数列表</span></span><br><span class="line"></span><br><span class="line">    print(<span class="number">3</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 输出：</span></span><br><span class="line"><span class="comment">// 0 1</span></span><br><span class="line"><span class="comment">// 0 1 2</span></span><br></pre></td></tr></table></figure></h2><h1 id="C-的可变参数-1"><a href="#C-的可变参数-1" class="headerlink" title="C++ 的可变参数"></a>C++ 的可变参数</h1><h2 id="参数列表-va-list-4组宏-1"><a href="#参数列表-va-list-4组宏-1" class="headerlink" title="参数列表 #va_list 4组宏"></a>参数列表 #va_list 4组宏</h2><p>见 “C 的可变参数” 内容。</p>
<hr>
<h2 id="初始化列表-initializer-list-类模板"><a href="#初始化列表-initializer-list-类模板" class="headerlink" title="初始化列表 initializer_list&lt;&gt; 类模板"></a>初始化列表 initializer_list&lt;&gt; 类模板</h2><p>头文件</p>
<ul>
<li><initializer_list></li>
</ul>
<p>原理</p>
<ul>
<li>类比容器 vector&lt;&gt; </li>
<li>比容器轻量</li>
<li>封装参数（指向参数的指针、参数的数量和参数的类型等）的<strong>包装器&#x2F;对象</strong></li>
</ul>
<p>缺点</p>
<ul>
<li>代码逻辑需要明确参数的类型</li>
<li><strong>一个</strong> initializer_list&lt;&gt; 对象只支持<strong>一种</strong>类型（可以使用<strong>多个</strong> initializer_list&lt;&gt; 对象<strong>按序</strong>支持<strong>多种</strong>类型）</li>
</ul>
<blockquote>
<p>按序：如一个 initializer_list&lt;int&gt; 对象表示一部分参数都是 int 类型，另一个 initializer_list&lt;string&gt; 对象表示另一部分参数都是 string 类型；不能是一个 initializer_list&lt;int&gt; 对象表示一部分参数既有 int 类型又有 string 类型</p>
</blockquote>
<ul>
<li>…</li>
</ul>
<p>代码示例</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// #include &lt;initializer_list&gt; // initializer_list&lt;&gt;</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> std::cout;</span><br><span class="line"><span class="keyword">using</span> std::endl;</span><br><span class="line"><span class="keyword">using</span> std::initializer_list;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">print</span><span class="params">(initializer_list&lt;<span class="type">int</span>&gt; li)</span> <span class="comment">// 使用 initializer_list&lt;&gt; 对象接收可变参数</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="type">int</span> l : li)</span><br><span class="line">    &#123;</span><br><span class="line">        cout &lt;&lt; l &lt;&lt; <span class="string">&quot; &quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    cout &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(&#123;<span class="number">0</span>, <span class="number">1</span>&#125;); <span class="comment">// 使用列表初始化创建匿名 initializer_list&lt;&gt; 对象并作为参数</span></span><br><span class="line">    <span class="built_in">print</span>(&#123;<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>&#125;);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 输出：</span></span><br><span class="line"><span class="comment">// 0 1</span></span><br><span class="line"><span class="comment">// 0 1 2</span></span><br></pre></td></tr></table></figure>
<hr>
<h2 id="可变参数模板"><a href="#可变参数模板" class="headerlink" title="可变参数模板"></a>可变参数模板</h2><p>相关语法</p>
<ul>
<li>typename…：定义模板参数包</li>
<li>Args：<strong>模板参数（抽象概念）</strong> 包的名称，可自定义名称，表示任意类型和数量的模板参数</li>
<li>Args…：模板参数包</li>
<li>args：<strong>具体参数（具体概念）</strong> 包的名称，可自定义名称，表示任意类型和数量的具体参数</li>
<li>args…：展开具体参数包</li>
<li>sizeof…(具体参数包)：获取具体参数包参数的数量</li>
<li>…：折叠表达式</li>
</ul>
<blockquote>
<p>折叠表达式的概念和语法较复杂 <strong>（作者觉得很怪异）</strong>，在此不深入讲解。<br>可参见：<a target="_blank" rel="noopener" href="https://blog.csdn.net/baidu_41388533/article/details/109621822">（C++模板编程）：折叠表达式、可变参表达式_c++模板折叠-CSDN博客</a></p>
</blockquote>
<p>解包方式</p>
<ul>
<li>递归展开1</li>
<li>递归展开2（C++ 17支持）</li>
<li>逗号表达式展开1</li>
<li>逗号表达式展开2（优化）</li>
<li>逗号表达式3（优化）</li>
<li>折叠表达式展开（C++ 17支持）</li>
</ul>
<p>缺点</p>
<ul>
<li>概念较复杂</li>
<li>语法较复杂</li>
<li>…</li>
</ul>
<p>获取具体参数包参数的数量</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> std::cout;</span><br><span class="line"><span class="keyword">using</span> std::endl;</span><br><span class="line"></span><br><span class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span>... Args&gt;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">print</span><span class="params">(Args... args)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    cout &lt;&lt; <span class="keyword">sizeof</span>...(args) &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>); <span class="comment">// 2个不同类型的参数</span></span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>, <span class="string">&quot;str&quot;</span>); <span class="comment">// 3个不同类型的参数</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">输出：</span></span><br><span class="line"><span class="comment">2</span></span><br><span class="line"><span class="comment">3</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">逐行解释：</span></span><br><span class="line"><span class="comment">2：具体参数包参数的数量是2</span></span><br><span class="line"><span class="comment">3：具体参数包参数的数量是3</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>



<p>递归展开1</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> std::cout;</span><br><span class="line"><span class="keyword">using</span> std::endl;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 参数数量 == 1的函数模板</span></span><br><span class="line"><span class="comment">// 递归终止时调用</span></span><br><span class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">print</span><span class="params">(T value)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    cout &lt;&lt; value &lt;&lt; endl; <span class="comment">// 参数值</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 可变参数模板</span></span><br><span class="line"><span class="comment">// 参数数量 &gt; 1的函数模板</span></span><br><span class="line"><span class="comment">// 递归时调用</span></span><br><span class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T, <span class="keyword">typename</span>... Args&gt;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">print</span><span class="params">(T value, Args... args)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    cout &lt;&lt; value &lt;&lt; <span class="string">&quot; &quot;</span>; <span class="comment">// 参数值</span></span><br><span class="line"></span><br><span class="line">    <span class="built_in">print</span>(args...); <span class="comment">// 递归调用</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>);        <span class="comment">// 2个不同类型的参数</span></span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>, <span class="string">&quot;str&quot;</span>); <span class="comment">// 3个不同类型的参数</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">输出：</span></span><br><span class="line"><span class="comment">0 c</span></span><br><span class="line"><span class="comment">0 c str</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>
<p>递归展开2（C++ 17支持）</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> std::cout;</span><br><span class="line"><span class="keyword">using</span> std::endl;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 可变参数模板</span></span><br><span class="line"><span class="comment">// 参数数量 &gt;= 1的函数模板</span></span><br><span class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T, <span class="keyword">typename</span>... Args&gt;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">print</span><span class="params">(T value, Args... args)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    cout &lt;&lt; value &lt;&lt; <span class="string">&quot; &quot;</span>; <span class="comment">// 参数值</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 参数数量为0时无法递归调用：print(args...);，需要递归终止</span></span><br><span class="line">    <span class="comment">// C++ 17标准支持“if constexpr()”语法，可以在编译而不是运行时求值以终止递归，使得编译通过</span></span><br><span class="line">    <span class="function"><span class="keyword">if</span> <span class="title">constexpr</span> <span class="params">(<span class="keyword">sizeof</span>...(args) &gt; <span class="number">0</span>)</span> <span class="comment">// 递归调用</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="built_in">print</span>(args...);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span> <span class="comment">// 递归终止</span></span><br><span class="line">    &#123;</span><br><span class="line">        cout &lt;&lt; endl;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>);        <span class="comment">// 2个不同类型的参数</span></span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>, <span class="string">&quot;str&quot;</span>); <span class="comment">// 3个不同类型的参数</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">输出：</span></span><br><span class="line"><span class="comment">0 c</span></span><br><span class="line"><span class="comment">0 c str</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>
<p>逗号表达式展开1</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="comment">// #include &lt;initializer_list&gt;  // initializer_list&lt;&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> std::cout;</span><br><span class="line"><span class="keyword">using</span> std::endl;</span><br><span class="line"><span class="keyword">using</span> std::initializer_list;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 可变参数模板</span></span><br><span class="line"><span class="comment">// 参数数量 &gt;= 1的函数模板</span></span><br><span class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T, <span class="keyword">typename</span>... Args&gt;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">print</span><span class="params">(T value, Args... args)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    cout &lt;&lt; value &lt;&lt; <span class="string">&quot; &quot;</span>; <span class="comment">// 第一个参数值</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 重点理解：</span></span><br><span class="line">    <span class="comment">// [args]&#123;cout &lt;&lt; args &lt;&lt; &quot; &quot;;&#125;：Lambda 表达式</span></span><br><span class="line">    <span class="comment">// [args]&#123;cout &lt;&lt; args &lt;&lt; &quot; &quot;;&#125;()：调用 Lambda 表达式</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// value：第一个参数的值</span></span><br><span class="line">    <span class="comment">// (,)：逗号表达式：先计算左表达式，再计算右表达式，结果是右表达式的值</span></span><br><span class="line">    <span class="comment">// ([args]&#123;cout &lt;&lt; args &lt;&lt; &quot; &quot;;&#125;(), value)：先调用 Lambda 表达式，再计算第一个参数的值，结果是第一个参数的值</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// args...：展开具体参数包</span></span><br><span class="line">    <span class="comment">// ([args]&#123;cout &lt;&lt; args &lt;&lt; &quot; &quot;;&#125;(), value)...：展开具体参数包，对每一个参数，先调用 Lambda 表达式，再计算第一个参数值，结果是第一个参数值</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// typename T：第一个参数的类型</span></span><br><span class="line">    <span class="comment">// initializer_list&lt;&gt;&#123;&#125;：initializer_list&lt;&gt; 对象</span></span><br><span class="line">    <span class="comment">// initializer_list&lt;T&gt;&#123;&#125;：匿名 initializer_list&lt;&gt; 对象，值类型是第一个参数的类型</span></span><br><span class="line">    <span class="comment">// initializer_list&lt;T&gt;&#123;([args]&#123;cout &lt;&lt; args &lt;&lt; &quot; &quot;;&#125;(), value)...&#125;;：第一个参数作为匿名 initializer_list&lt;&gt; 对象的值，值类型是第一个参数的类型</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// C++11 和 C++14 标准，没有提供一种直接将具体参数包展开到函数调用参数列表中的语法</span></span><br><span class="line">    <span class="comment">// 所以可以使用 initializer_list&lt;&gt; 结合 args... 展开具体参数包</span></span><br><span class="line">    <span class="comment">// 又因为 initializer_list&lt;&gt; 的值需要相同类型</span></span><br><span class="line">    <span class="comment">// 所以可以使用逗号表达式，无论左表达式怎么计算，都返回第一个参数的类型和值 T value</span></span><br><span class="line">    <span class="comment">// 所以函数模板需要定义 typename T，函数需要定义 T value</span></span><br><span class="line">    initializer_list&lt;T&gt;&#123;([args]</span><br><span class="line">                         &#123; cout &lt;&lt; args &lt;&lt; <span class="string">&quot; &quot;</span>; &#125;(),</span><br><span class="line">                         value)...&#125;;</span><br><span class="line">    cout &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>);        <span class="comment">// 2个不同类型的参数</span></span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>, <span class="string">&quot;str&quot;</span>); <span class="comment">// 3个不同类型的参数</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">输出：</span></span><br><span class="line"><span class="comment">0 c</span></span><br><span class="line"><span class="comment">0 c str</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>

<p>逗号表达式展开2（优化）</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="comment">// #include &lt;initializer_list&gt;  // initializer_list&lt;&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> std::cout;</span><br><span class="line"><span class="keyword">using</span> std::endl;</span><br><span class="line"><span class="keyword">using</span> std::initializer_list;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 可变参数模板</span></span><br><span class="line"><span class="comment">// 参数数量 &gt;= 1的函数模板</span></span><br><span class="line"><span class="comment">// 依据“逗号表达式展开1”的分析，模板参数 typename T、初始化列表 initializer_list&lt;&gt; 的类型 T、第一个参数值 value 和逗号表达式的右表达式 value 有意义但无用途，可以优化</span></span><br><span class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span>... Args&gt;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">print</span><span class="params">(Args... args)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    initializer_list&lt;<span class="type">int</span>&gt;&#123;([args]</span><br><span class="line">                           &#123; cout &lt;&lt; args &lt;&lt; <span class="string">&quot; &quot;</span>; &#125;(),</span><br><span class="line">                           <span class="number">0</span>)...&#125;;</span><br><span class="line">    cout &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>);        <span class="comment">// 2个不同类型的参数</span></span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>, <span class="string">&quot;str&quot;</span>); <span class="comment">// 3个不同类型的参数</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">输出：</span></span><br><span class="line"><span class="comment">0 c</span></span><br><span class="line"><span class="comment">0 c str</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>
<p>逗号表达式展开3（优化）</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;vector&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> std::cout;</span><br><span class="line"><span class="keyword">using</span> std::endl;</span><br><span class="line"><span class="keyword">using</span> std::vector;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 可变参数模板</span></span><br><span class="line"><span class="comment">// 参数数量 &gt;= 1的函数模板</span></span><br><span class="line"><span class="comment">// 依据“逗号表达式展开1”的分析，对于可以使用列表初始化 &#123;&#125; 的对象，数组和向量 vector&lt;&gt; 等，可以结合 args... 展开具体参数包</span></span><br><span class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span>... Args&gt;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">print</span><span class="params">(Args... args)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="type">int</span> arr[]&#123;([args]</span><br><span class="line">               &#123; cout &lt;&lt; args &lt;&lt; <span class="string">&quot; &quot;</span>; &#125;(),</span><br><span class="line">               <span class="number">0</span>)...&#125;;</span><br><span class="line">    cout &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">    vector&lt;<span class="type">int</span>&gt;&#123;([args]</span><br><span class="line">                 &#123; cout &lt;&lt; args &lt;&lt; <span class="string">&quot; &quot;</span>; &#125;(),</span><br><span class="line">                 <span class="number">0</span>)...&#125;;</span><br><span class="line">    cout &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>);        <span class="comment">// 2个不同类型的参数</span></span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>, <span class="string">&quot;str&quot;</span>); <span class="comment">// 3个不同类型的参数</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">输出：</span></span><br><span class="line"><span class="comment">0 c</span></span><br><span class="line"><span class="comment">0 c</span></span><br><span class="line"><span class="comment">0 c str</span></span><br><span class="line"><span class="comment">0 c str</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>


<p>折叠表达式展开（C++ 17支持）</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> std::cout;</span><br><span class="line"><span class="keyword">using</span> std::endl;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 可变参数模板</span></span><br><span class="line"><span class="comment">// 参数数量 &gt;= 1的函数模板</span></span><br><span class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span>... Args&gt;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">print</span><span class="params">(Args... args)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">// 二元左折叠表达式（概念复杂）</span></span><br><span class="line">    <span class="comment">// (,)：逗号表达式：连接折叠表达式和操作</span></span><br><span class="line">    <span class="comment">// 对每一个参数，先输出参数，再输出空格</span></span><br><span class="line">    (..., (cout &lt;&lt; args &lt;&lt; <span class="string">&#x27; &#x27;</span>));</span><br><span class="line">    cout &lt;&lt; endl;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>);        <span class="comment">// 2个不同类型的参数</span></span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>, <span class="string">&#x27;c&#x27;</span>, <span class="string">&quot;str&quot;</span>); <span class="comment">// 3个不同类型的参数</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">输出：</span></span><br><span class="line"><span class="comment">0 c</span></span><br><span class="line"><span class="comment">0 c str</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>


<hr>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>C 和 C++ 可变参数介绍。</p>
<hr>
<h1 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h1><ul>
<li><a target="_blank" rel="noopener" href="https://www.runoob.com/cprogramming/c-variable-arguments.html">C 可变参数 | 菜鸟教程 (runoob.com)</a></li>
<li><a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV11N411Y79G?p=2&vd_source=9ac1c0a6d496218112b60d49bc768cd7">02_可变长参数的基础_哔哩哔哩_bilibili</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/ZKR_HN/article/details/99558135">va_list原理及用法-CSDN博客</a></li>
<li><a target="_blank" rel="noopener" href="https://www.cnblogs.com/ofnoname/p/16524932.html#tp2">C++ 实现可变参数的三个方法 - Ofnoname - 博客园 (cnblogs.com)</a></li>
<li><a target="_blank" rel="noopener" href="https://changkun.de/modern-cpp/zh-cn/02-usability/#%E5%8F%98%E9%95%BF%E5%8F%82%E6%95%B0%E6%A8%A1%E6%9D%BF">第 2 章 语言可用性的强化 现代 C++ 教程: 高速上手 C++ 11&#x2F;14&#x2F;17&#x2F;20 - Modern C++ Tutorial: C++ 11&#x2F;14&#x2F;17&#x2F;20 On the Fly (changkun.de)</a></li>
<li><a target="_blank" rel="noopener" href="https://www.cnblogs.com/pandamohist/p/13856489.html">c++11之函数参数包展开 - mohist - 博客园 (cnblogs.com)</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/baidu_41388533/article/details/109621822">（C++模板编程）：折叠表达式、可变参表达式_c++模板折叠-CSDN博客</a></li>
</ul>
<hr>
<h1 id="作者的话"><a href="#作者的话" class="headerlink" title="作者的话"></a>作者的话</h1><ul>
<li><strong>感谢参考资料的作者&#x2F;博主</strong></li>
<li>作者：夜悊</li>
<li>版权所有，转载请注明出处，谢谢~</li>
<li><strong>如果文章对你有帮助，请点个赞或加个粉丝吧，你的支持就是作者的动力~</strong></li>
<li>文章在描述时有疑惑的地方，请留言，定会一一耐心讨论、解答</li>
<li>文章在认识上有错误的地方, 敬请批评指正</li>
<li>望读者们都能有所收获</li>
</ul>
<hr>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="http://example.com">夜悊</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="http://example.com/2023/11/08/C%20%E5%92%8C%20C++%20%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0%E4%BB%8B%E7%BB%8D/">http://example.com/2023/11/08/C 和 C++ 可变参数介绍/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">夜悊的技术小宅</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/C/">C++</a></div><div class="post_share"><div class="social-share" data-image="/img/cover6.png" data-sites="qq,wechat,weibo"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1.1.3/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1.1.3/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/11/06/C++%20%E4%BB%A3%E7%A0%81%E5%AE%9E%E4%BE%8B%EF%BC%9A%E5%B9%B6%E6%9F%A5%E9%9B%86%E7%AE%80%E5%8D%95%E5%88%9B%E5%BB%BA%E5%B7%A5%E5%85%B7/" title="C++ 代码实例：并查集简单创建工具"><img class="cover" src= "" data-lazy-src="/img/cover15.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">C++ 代码实例：并查集简单创建工具</div></div></a></div><div class="next-post pull-right"><a href="/2023/11/19/%E7%AE%80%E5%8D%95%E5%B7%A5%E5%8E%82%E3%80%81%E5%B7%A5%E5%8E%82%E6%96%B9%E6%B3%95%E5%92%8C%E6%8A%BD%E8%B1%A1%E5%B7%A5%E5%8E%82%E6%A8%A1%E5%BC%8F%EF%BC%88%E5%88%9B%E5%BB%BA%E5%9E%8B%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%EF%BC%89%E7%9A%84%20C++%20%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B%E6%A8%A1%E6%9D%BF/" title="简单工厂、工厂方法和抽象工厂模式（创建型设计模式）的 C++ 代码示例模板"><img class="cover" src= "" data-lazy-src="/img/cover8.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">简单工厂、工厂方法和抽象工厂模式（创建型设计模式）的 C++ 代码示例模板</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2023/11/03/C++%20STL%20%E5%85%AD%E7%BB%84%E4%BB%B6%E4%BB%8B%E7%BB%8D/" title="C++ STL 六组件介绍"><img class="cover" src= "" data-lazy-src="/img/cover12.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-11-03</div><div class="title">C++ STL 六组件介绍</div></div></a></div><div><a href="/2023/10/01/C++%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B%EF%BC%9A%E6%8E%92%E5%88%97%E6%95%B0%E7%AE%80%E5%8D%95%E7%94%9F%E6%88%90%E5%B7%A5%E5%85%B7/" title="C++代码示例：排列数简单生成工具"><img class="cover" src= "" data-lazy-src="/img/cover15.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-10-01</div><div class="title">C++代码示例：排列数简单生成工具</div></div></a></div><div><a href="/2023/11/05/C++%20%E4%BB%A3%E7%A0%81%E5%AE%9E%E4%BE%8B%EF%BC%9A%E5%A4%9A%E9%A1%B9%E5%BC%8F%E9%99%A4%E6%B3%95%E7%AE%80%E5%8D%95%E8%AE%A1%E7%AE%97%E5%B7%A5%E5%85%B7/" title="C++ 代码实例：多项式除法简单计算工具"><img class="cover" src= "" data-lazy-src="/img/cover17.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-11-05</div><div class="title">C++ 代码实例：多项式除法简单计算工具</div></div></a></div><div><a href="/2023/09/28/C++%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B%EF%BC%9A%E7%BB%84%E5%90%88%E6%95%B0%E7%AE%80%E5%8D%95%E7%94%9F%E6%88%90%E5%B7%A5%E5%85%B7/" title="C++代码示例：组合数简单生成工具"><img class="cover" src= "" data-lazy-src="/img/cover6.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-09-28</div><div class="title">C++代码示例：组合数简单生成工具</div></div></a></div><div><a href="/2023/11/06/C++%20%E4%BB%A3%E7%A0%81%E5%AE%9E%E4%BE%8B%EF%BC%9A%E5%B9%B6%E6%9F%A5%E9%9B%86%E7%AE%80%E5%8D%95%E5%88%9B%E5%BB%BA%E5%B7%A5%E5%85%B7/" title="C++ 代码实例：并查集简单创建工具"><img class="cover" src= "" data-lazy-src="/img/cover15.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-11-06</div><div class="title">C++ 代码实例：并查集简单创建工具</div></div></a></div><div><a href="/2023/10/02/C++%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B%EF%BC%9A%E8%BF%9B%E5%88%B6%E6%95%B0%E7%AE%80%E5%8D%95%E7%94%9F%E6%88%90%E5%B7%A5%E5%85%B7/" title="C++代码示例：进制数简单生成工具"><img class="cover" src= "" data-lazy-src="/img/cover17.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-10-02</div><div class="title">C++代码示例：进制数简单生成工具</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%89%8D%E8%A8%80"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%A6%82%E5%BF%B5"><span class="toc-number">2.</span> <span class="toc-text">概念</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#C-%E7%9A%84%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0"><span class="toc-number">3.</span> <span class="toc-text">C 的可变参数</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%82%E6%95%B0%E5%88%97%E8%A1%A8-va-list-4%E7%BB%84%E5%AE%8F"><span class="toc-number">3.1.</span> <span class="toc-text">参数列表 #va_list 4组宏</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B"><span class="toc-number">3.2.</span> <span class="toc-text">代码示例1234567891011121314151617181920212223242526272829303132333435363738394041#include &lt;stdarg.h&gt; &#x2F;&#x2F; #va_list、#va_start()、#va_arg()、#va_end()#include &lt;stdio.h&gt;&#x2F;&#x2F; 形参的一般形式：&#x2F;&#x2F; num：参数数量&#x2F;&#x2F; ...：参数列表void print(int num, ...){    &#x2F;&#x2F; 1. 定义 va_list    va_list para_list; &#x2F;&#x2F; 类型宏；参数列表    &#x2F;&#x2F; 2. 初始化 va_list    va_start(para_list, num); &#x2F;&#x2F; 函数宏；va_list 指向参数列表的第一个参数    &#x2F;&#x2F; 3. 遍历 va_list    for (int i &#x3D; 0; i &lt; num; ++i)    {        printf(&quot;%d &quot;, va_arg(para_list, int)); &#x2F;&#x2F; 函数宏；依据类型，va_list 指向参数列表的下一个参数    }    printf(&quot;\n&quot;);    &#x2F;&#x2F; 4. 清理 va_list    va_end(para_list); &#x2F;&#x2F; 函数宏；清理 va_list    return;}int main(){    print(2, 0, 1);    &#x2F;&#x2F; 实参的一般形式：    &#x2F;&#x2F; 2：参数数量    &#x2F;&#x2F; 0 1：参数列表    print(3, 0, 1, 2);    return 0;}&#x2F;&#x2F; 输出：&#x2F;&#x2F; 0 1&#x2F;&#x2F; 0 1 2</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#C-%E7%9A%84%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0-1"><span class="toc-number">4.</span> <span class="toc-text">C++ 的可变参数</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%82%E6%95%B0%E5%88%97%E8%A1%A8-va-list-4%E7%BB%84%E5%AE%8F-1"><span class="toc-number">4.1.</span> <span class="toc-text">参数列表 #va_list 4组宏</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8-initializer-list-%E7%B1%BB%E6%A8%A1%E6%9D%BF"><span class="toc-number">4.2.</span> <span class="toc-text">初始化列表 initializer_list&lt;&gt; 类模板</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0%E6%A8%A1%E6%9D%BF"><span class="toc-number">4.3.</span> <span class="toc-text">可变参数模板</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">5.</span> <span class="toc-text">总结</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99"><span class="toc-number">6.</span> <span class="toc-text">参考资料</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BD%9C%E8%80%85%E7%9A%84%E8%AF%9D"><span class="toc-number">7.</span> <span class="toc-text">作者的话</span></a></li></ol></div></div></div></div></main><footer id="footer" style="background-image: url('/img/cover6.png')"><div id="footer-wrap"><div class="copyright">&copy;2023 - 2025 By 夜悊</div><div class="footer_custom_text"><a target="_blank" href="https://beian.miit.gov.cn/" >琼ICP备2023001225号-1</a><br><img src= "" data-lazy-src="/img/beian.png"/>&nbsp<a target="_blank" href="https://www.beian.gov.cn/portal/registerSystemInfo?recordcode=46010802001221" >琼公网安备 46010802001221号</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="translateLink" type="button" title="简繁转换">繁</button><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js?v=4.13.0"></script><script src="/js/main.js?v=4.13.0"></script><script src="/js/tw_cn.js?v=4.13.0"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0.33/dist/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@17.8.8/dist/lazyload.iife.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js?v=4.13.0"></script></div></div></body></html>